import React from "react";
import { Form, Input, Button ,Toast} from "antd-mobile";
import http from "../../api/http";
function Index() {
  const onFinish = async (value) => {
    const res = await http.post("/api/login", value);
    const { code, data ,message} = res.data;
    if (code === 200) {
      localStorage.setItem("token", data.token);
      localStorage.setItem("userInfo", JSON.stringify(data.userInfo));
    }else{
      Toast.show({
        content: message,
        icon: "fail",
      });
    }
  };
  return (
    <div>
      <Form
        layout="horizontal"
        onFinish={onFinish}
        footer={
          <Button block type="submit" color="primary" size="large">
            提交
          </Button>
        }
      >
        <Form.Header>水平布局表单</Form.Header>
        <Form.Item
          name="username"
          label="手机号"
          rules={[{ required: true, message: "姓名不能为空" }]}
        >
          <Input placeholder="请输入姓名" />
        </Form.Item>
        <Form.Item
          name="password"
          label="验证码"
          rules={[{ required: true, message: "姓名不能为空" }]}
        >
          <Input placeholder="请输入姓名" />
        </Form.Item>
      </Form>
    </div>
  );
}

export default Index;
